package com.pcbly.web.components.utils.jfreechart;

import java.awt.Color; 
import java.awt.RenderingHints;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart; 
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

public class BarChart2D  extends AbstractChartFont{

	public CategoryDataset getDataSet() {
		String str = "学生人数";
		String s1 = "湖南";
		String s2 = "湖北";
		String s3 = "广东";
		String s4 = "上海";
		String s5 = "江苏";
		DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
		dataSet.addValue(300, str, s1);
		dataSet.addValue(300, str, s2);
		dataSet.addValue(400, str, s3);
		dataSet.addValue(190, str, s4);
		dataSet.addValue(230, str, s5);
		return dataSet;
	}

	/**
	 * 根据数据设置图表的相关信息
	 * 
	 * @param categoryDataset
	 * @return
	 */
	public JFreeChart createJFreeChart(CategoryDataset categoryDataset) {
		/**
		 * 设置图表的相关信息,其参数依次为： 图表标题,纵坐标显示提示,横坐标显示提示,要显示的数据
		 * 设置要显示图标柱状的横向或纵向.HORIZONTAL表示纵向,VERTICAL表示横向 后面三个boolean型的参数：
		 * 第一个表示是否显示柱状图例,true为显示,false为不显示
		 */
		try {
			String title = "学生人数统计"; 
			String province = "省份"; 
			String quarlity = "数量"; 
			
//			StandardChartTheme standardChartTheme = new StandardChartTheme("name");
//			standardChartTheme.setLargeFont(new Font("宋体",Font.BOLD, 10));//可以改变轴向的字体
//			standardChartTheme.setRegularFont(new Font("宋体",Font.BOLD, 15));//可以改变图例的字体
//			standardChartTheme.setExtraLargeFont(new Font("宋体",Font.BOLD, 24));//可以改变图标的标题字体
//			ChartFactory.setChartTheme(standardChartTheme);
			JFreeChart chart = ChartFactory.createBarChart(title, province,
					quarlity, categoryDataset, PlotOrientation.VERTICAL, true,
					true, false);
			
			this.configFont(chart);
			
			// 设置背景颜色
			chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
					RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

			chart.setBackgroundPaint(Color.WHITE);
			CategoryPlot cateforyPlot = chart.getCategoryPlot(); 
			
//			cateforyPlot.setOutlineVisible(true);
			cateforyPlot.setBackgroundPaint(Color.WHITE);
			cateforyPlot.setDomainGridlinePaint(Color.WHITE);
			// 设置是否可见
			cateforyPlot.setDomainGridlinesVisible(true);
			// 设置柱状的颜色
			cateforyPlot.setRangeGridlinePaint(Color.BLUE);
			return chart;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	// public String getFileName(){
	// String fileName = "";
	// JFreeChart chart=index();
	// ChartRenderingInfo chartInfo = new ChartRenderingInfo(
	// new StandardEntityCollection());
	// try{
	//			
	// }catch(Exception e){
	//			
	// }
	// return null;
	// }
	public JFreeChart index() {
		CategoryDataset dataset = getDataSet();
		JFreeChart chart=createJFreeChart(dataset);
		
		return chart;
	}
}